﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Touchscreen
{
    public partial class Stap2 : System.Web.UI.Page
    {
        public const string ImageFolder = "~/App_Themes/Images/";
        public const string FlagsFolder = "~/App_Themes/Images/Flags/";

        public string FilmName;
        public int AdultCounter = 0;
        public int ChildCounter = 0;
        public int OldPeopleCounter = 0;
        public int StudentCounter = 0;
        public int GlassesCounter = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            ButtonNext.Visible = false;
            FilmName = Request.QueryString["FilmName"];
            AdultCounter = Convert.ToInt32(Request.QueryString["Adult"]);
            ChildCounter = Convert.ToInt32(Request.QueryString["Child"]);
            OldPeopleCounter = Convert.ToInt32(Request.QueryString["OldPeople"]);
            StudentCounter = Convert.ToInt32(Request.QueryString["Student"]);
            GlassesCounter = Convert.ToInt32(Request.QueryString["3D"]);

            LabelAdultCounter.Text = AdultCounter.ToString();
            LabelChildCounter.Text = ChildCounter.ToString();
            LabelOldPeopleCounter.Text = OldPeopleCounter.ToString();
            LabelStudentCounter.Text = StudentCounter.ToString();
            Label3dCounter.Text = GlassesCounter.ToString();

            if(AdultCounter > 0 || ChildCounter > 0 || OldPeopleCounter > 0 || StudentCounter > 0 || GlassesCounter > 0)
            {
                ButtonNext.Visible = true;
                ButtonNext.PostBackUrl = "Stap3.aspx?FilmName=" + FilmName +
                                            "&Adult=" + AdultCounter +
                                            "&Child=" + ChildCounter +
                                            "&OldPeople=" + OldPeopleCounter +
                                            "&Student=" + StudentCounter +
                                            "&3D=" + GlassesCounter;
            }
        }

        private void UpdateCounter()
        {
            FilmName = Request.QueryString["FilmName"];
            string queryString = "?FilmName=" + FilmName +
                "&Adult=" + AdultCounter +
                "&Child=" + ChildCounter +
                "&OldPeople=" + OldPeopleCounter +
                "&Student=" + StudentCounter +
                "&3D=" + GlassesCounter;

            Response.Redirect("Stap2.aspx" + queryString);
        }

        protected void ImageButtonUp_Click(object sender, ImageClickEventArgs e)
        {
            AdultCounter = Convert.ToInt32(Request.QueryString["Adult"]);
            AdultCounter++;

            UpdateCounter();
        }

        protected void ImageButtonAdultDown_Click(object sender, ImageClickEventArgs e)
        {
            AdultCounter = Convert.ToInt32(Request.QueryString["Adult"]);
            if (AdultCounter > 0)
            {
                AdultCounter--;
            }
            UpdateCounter();
        }

        protected void ImageButtonChildUp_Click(object sender, ImageClickEventArgs e)
        {
            ChildCounter = Convert.ToInt32(Request.QueryString["Child"]);
            ChildCounter++;

            UpdateCounter();
        }

        protected void ImageButtonChildDown_Click(object sender, ImageClickEventArgs e)
        {
            ChildCounter = Convert.ToInt32(Request.QueryString["Child"]);
            if (ChildCounter > 0)
            {
                ChildCounter--;
            }
            UpdateCounter();
        }

        protected void ImageButtonOldPeopleUp_Click(object sender, ImageClickEventArgs e)
        {
            OldPeopleCounter = Convert.ToInt32(Request.QueryString["OldPeople"]);
            OldPeopleCounter++;

            UpdateCounter();
        }

        protected void ImageButtonOldPeopleDown_Click(object sender, ImageClickEventArgs e)
        {
            OldPeopleCounter = Convert.ToInt32(Request.QueryString["OldPeople"]);
            if (OldPeopleCounter > 0)
            {
                OldPeopleCounter--;
            }
            UpdateCounter();
        }

        protected void ImageButtonStudentUp_Click(object sender, ImageClickEventArgs e)
        {
            StudentCounter = Convert.ToInt32(Request.QueryString["Student"]);
            StudentCounter++;

            UpdateCounter();
        }

        protected void ImageButtonStudentDown_Click(object sender, ImageClickEventArgs e)
        {
            StudentCounter = Convert.ToInt32(Request.QueryString["Student"]);
            if (StudentCounter > 0)
            {
                StudentCounter--;
            }
            UpdateCounter();
        }

        protected void ImageButton3dUp_Click(object sender, ImageClickEventArgs e)
        {
            GlassesCounter = Convert.ToInt32(Request.QueryString["3D"]);
            GlassesCounter++;

            UpdateCounter();
        }

        protected void ImageButton3dDown_Click(object sender, ImageClickEventArgs e)
        {
            GlassesCounter = Convert.ToInt32(Request.QueryString["3D"]);
            if (GlassesCounter > 0)
            {
                GlassesCounter--;
            }
            UpdateCounter();
        }

        protected void ButtonNext_Click(object sender, EventArgs e)
        {

        }
    }
}